<template>
	<view>
		<uni-swipe-action v-if="list.length>0">
			<uni-swipe-action-item v-for="(item,index) in list" :options="options" :key="index" @change="swipeChange" @click="swipeClick($event,index)">
				<media-list type="one" :item="item" :index="index"></media-list>
			</uni-swipe-action-item>
		</uni-swipe-action>
		<!-- 默认样式 -->
		<view v-else class="flex w-100 align-center justify-center text-secondary" style="height: 100rpx;">
			暂无历史记录
		</view>
	</view>
</template>

<script>
	import mediaList from '@/components/common/media-list.vue';
	import uniSwipeAction from '@/components/uni-ui/uni-swipe-action/uni-swipe-action.vue'
	import uniSwipeActionItem from '@/components/uni-ui/uni-swipe-action-item/uni-swipe-action-item.vue'
	import {mapState} from 'vuex';
	export default {
		components: {
			mediaList,
			uniSwipeAction,
			uniSwipeActionItem
		},
		computed:{
			...mapState({
				user_id:state=>{
					return state.user?state.user.id:0
				}
			})
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: 'rgb(255,58,49)'
					}
				}],
				list:[],
			}
		},
		onLoad() {
			this.getData()
		},
		onNavigationBarButtonTap() {
			uni.removeStorage({
				key:'history',
				success:()=>{
					uni.showToast({
						title: '清除成功'
					});
				}
			})
		},
		methods: {
			
			getData(){
				this.list = uni.getStorageSync('history') ? JSON.parse(uni.getStorageSync('history')) : []
			},
			swipeChange(e) {
				console.log('返回：', e);
			},
			swipeClick(e, index) {
				this.list.splice(index,1)
				uni.showToast({
					title: '删除成功'
				});
				uni.setStorageSync('history', JSON.stringify(this.list))
			}
		}
	}
</script>

<style>

</style>
